<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class PickupManagementMenuSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // 检查是否已存在自提点管理菜单
        $existingMenu = DB::table('admin_menu')->where('title', '自提点管理')->first();
        
        if (!$existingMenu) {
            // 获取最大排序值
            $maxOrder = DB::table('admin_menu')->max('order') ?? 0;
            
            // 添加主菜单项 - 自提点管理
            $parentId = DB::table('admin_menu')->insertGetId([
                'parent_id' => 0,
                'order' => $maxOrder + 1,
                'title' => '自提点管理',
                'icon' => 'fa-list-ul',
                'uri' => '',
                'created_at' => now(),
                'updated_at' => now(),
            ]);
            
            // 添加子菜单项
            $subMenus = [
                [
                    'title' => '自提点清单',
                    'icon' => 'fa-list-ul',
                    'uri' => '/pickup',
                    'order_offset' => 1
                ],
                [
                    'title' => '申请列表',
                    'icon' => 'fa-file-alt',
                    'uri' => '/pickup-applications',
                    'order_offset' => 2
                ],
                [
                    'title' => '提成明细',
                    'icon' => 'fa-money-bill-wave',
                    'uri' => '/pickup-commissions',
                    'order_offset' => 3
                ]
            ];
            
            foreach ($subMenus as $menu) {
                DB::table('admin_menu')->insert([
                    'parent_id' => $parentId,
                    'order' => $maxOrder + 1 + $menu['order_offset'],
                    'title' => $menu['title'],
                    'icon' => $menu['icon'],
                    'uri' => $menu['uri'],
                    'created_at' => now(),
                    'updated_at' => now(),
                ]);
            }
            
            $this->command->info('自提点管理菜单已成功添加！');
            $this->command->info('包含以下子菜单：');
            $this->command->info('- 自提点清单 (fa-list-ul)');
            $this->command->info('- 申请列表 (fa-file-alt)');
            $this->command->info('- 提成明细 (fa-money-bill-wave)');
        } else {
            $this->command->info('自提点管理菜单已存在，跳过添加。');
        }
    }
}